package cn.jlonely.xyhx.admin.controller;

import cn.jlonely.xyhx.admin.service.VitoService;
import cn.jlonely.xyhx.pojo.vo.ReviewVo;
import cn.jlonely.xyhx.utils.Result;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/admin")
public class VitoController {

    /**
     * 获取某个投票的排名
     */
    @Autowired
    private VitoService vitoService;

    @GetMapping("/getvitoInfo")
    public Result getVitoInfo(@RequestParam("id") Integer id) {
        List<ReviewVo> vitoInfo = vitoService.getVitoInfo(id);
        return Result.success(vitoInfo);
    }

    /**
     * 导出投票数据到Excel
     * @param id
     * @throws IOException
     */
    @GetMapping("/export/excel")
    public void exportExcel(HttpServletResponse response, @RequestParam("id") Integer id) throws IOException {
        vitoService.exportToExcel(response, id);
    }
}
